-
Notifications
You must be signed in to change notification settings - Fork 121
[ABTesting] Cache variations of logged out context experiments #8806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ABTesting] Cache variations of logged out context experiments #8806
Conversation
… for reading ABTest.
…ntication is turned on.
…VariationProvider`
You can test the changes from this Pull Request by:
|
| } | ||
|
|
||
| public func variation(for abTest: ABTest) -> Variation { | ||
| guard abTest.context == .loggedOut else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: should we leave a comment on why we are caching only for the logged-out context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we need to restrict to logged-out experiments only 🤔 We are requesting only experiments for specific contexts so it should be safe to apply this for all contexts right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are requesting only experiments for specific contexts so it should be safe to apply this for all contexts right?
I hope you mean that we only request experiments for current contexts from the server. Yes, I agree.
But, I would still prefer only to cache logged-out experiments to minimize the impact of this change. Also, we don't face any crossover issues with logged-in experiments.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, please go ahead with this solution 👍
| let cache = VariationCache(userDefaults: userDefaults) | ||
|
|
||
| // When | ||
| try cache.assign(variation: .treatment, for: .applicationPasswordAuthentication) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: should we create mock tests instead to avoid having to update this test when the experiment is removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| let cache = VariationCache(userDefaults: userDefaults) | ||
|
|
||
| // When | ||
| XCTAssertThrowsError(try cache.assign(variation: .treatment, for: .aaTestLoggedIn)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Same comment as above about mocking A/B test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if let cachedVariation = cache.variation(for: abTest) { | ||
| return cachedVariation | ||
| } else if let variation = abTest.variation { | ||
| try? cache.assign(variation: variation, for: abTest) | ||
| return variation | ||
| } else { | ||
| return .control | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should prioritize fresh values, i.e. getting the variation from abTest and only use cache as the fallback. That way we always get the latest values:
| if let cachedVariation = cache.variation(for: abTest) { | |
| return cachedVariation | |
| } else if let variation = abTest.variation { | |
| try? cache.assign(variation: variation, for: abTest) | |
| return variation | |
| } else { | |
| return .control | |
| } | |
| if let variation = abTest.variation { | |
| try? cache.assign(variation: variation, for: abTest) | |
| return variation | |
| } else if let cachedVariation = cache.variation(for: abTest) { | |
| return cachedVariation | |
| } else { | |
| return .control | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in c0708bf
Earlier, I prioritised cached value to display that we return the cached value if it is available. Because, for a logged-out experiment, it is perfectly valid to get the variation value only once and use it without refresh.
itsmeichigo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Generated by 🚫 dangerJS |
Closes: #8782
controlAutomattic/Automattic-Tracks-iOS#247Description
Raising this PR based on the solution we reached after discussions in this PR - #8788
We are caching the variation values of logged-out experiments to try to address the high crossovers that we see in Explat.
As this PR targets the release branch, I have cherry-picked commits from this PR #8769. This is done to import
ABTestVariationProviderTesting instructions
treatmentvariation for thewoocommerceios_login_rest_api_project_202301_v2experiment and you can test this PR (If not, you need to use a sandbox to force a variation. You can follow the instructions from this PR to assign a variation to your device.)treatmentvariation.Screenshots
NA
RELEASE-NOTES.txtif necessary.